﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibEBML.Common;
namespace MKVSplitter
{
    class Program
    {
        static void Main(string[] args)
        {
            string Filename = @"f:\videos\[age_Fansub][Muv-Luv_Alternative_Chronicles_01][PV2][GB][x264_ac3][HD][7F7F59A2].mkv";
            //string Filename = @"F:\TDDOWNLOAD\Godonlyknows.mkv";
            using (var reader = System.IO.File.OpenRead(Filename))
            {
                using (var buffer = new System.IO.BufferedStream(reader))
                {
                    EBMLDocument document = new EBMLDocument(buffer);
                    Matroska mts = new Matroska(document);
                    Segment seg = mts.Segment;
                    var Clusters = seg.Clusters;
                    var ss = Clusters.Where(m => m.Blocks.Any(ms => ms.TrackNumber == 2));
                    //var audios = ss.Select(m => m.Blocks.Where(mt => mt.TrackNumber == 2));
                    foreach (var item in ss)
                    {
                        var bs = item.Blocks.Where(mt => mt.TrackNumber == 2);
                        foreach (var item1 in bs)
                        {
                            if (item1 is Block)
                            {
                                var b = item1 as Block;
                                Console.WriteLine("Block Time={0},Reference={1}", b.TimeCode, b.ReferenceBlock);
                            }
                            else
                            {
                                Console.WriteLine("SimpleBlock Time={0}", item1.TimeCode);
                            }
                        }
                    }
                }
                string str = "FF00 0100 C05D0000 E02E0000 0400 1000 0500 130856E598";
                string str2 = "FF00 0200 80BB0000 E02E0000 0400 1000 0200 1190";
                string str3 = "FF00 0200 44AC0000 20620500 0400 1000 0200 1210";
                Console.ReadLine();
            }
        }
    }
}
